from typing import Optional
from datetime import datetime
from pydantic import BaseModel, EmailStr, constr

# 用户基础模型
class UserBase(BaseModel):
    username: str
    email: EmailStr
    role: Optional[str] = "user"
    status: Optional[str] = "启用"

# 创建用户请求模型
class UserCreate(UserBase):
    password: constr(min_length=6)

# 更新用户请求模型
class UserUpdate(BaseModel):
    username: Optional[str] = None
    email: Optional[EmailStr] = None
    password: Optional[constr(min_length=6)] = None
    role: Optional[str] = None
    status: Optional[str] = None

# 用户响应模型
class User(UserBase):
    id: int
    create_time: datetime
    update_time: datetime

    class Config:
        from_attributes = True

# 用户列表查询参数模型
class UserQueryParams(BaseModel):
    username: Optional[str] = None
    role: Optional[str] = None
    status: Optional[str] = None
    page: int = 1
    page_size: int = 10

# 用户列表响应模型
class UserList(BaseModel):
    items: list[User]
    total: int 